<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
<?php 
$layout = explode('&&&', file_get_contents('layout.html'));
echo $layout[0];

session_start();
if (!(isset($_SESSION['username'])))
	header("location:login.php");
?>

<html>
<head>
<script language="JavaScript" src="calendar3.js"></script>
</head>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<body>

<!-- Begin Main Column -->

<div id="mainContent">
	
	<h2>Restore & Continue Event Creation</h2>
        <form id="form1" method="post" action="">
    <table width="200" border="0">
            <tr>
              <td>Date:</td>
              <td><label>
                <input name="date" type="text" id="date" size="10" maxlength="10" />
                <a href="javascript:cal.popup();"><img src="img/cal.gif" /></a>
              </label></td>
            </tr>
          </table>
          <p>
            <label>
            <input type="submit" name="workshop_search" id="workshop_search" value="Search" class="button"/>
            </label>
    </p>
        </form>
        
        <script>var cal = new calendar3(document.forms['form1'].elements['date']);</script>
        
        <?php
	 	if($_POST) {
			$date=$_POST['date'];
			
			ob_start();
			$host="localhost"; // Host name
			$username="root"; // Mysql username
			$password=""; // Mysql password
			$db_name="rtl"; // Database name
			
			// Connect to server and select databse.
			mysql_connect("$host", "$username", "$password")or die("cannot connect");
			mysql_select_db("$db_name")or die("cannot select DB");
			
			if($date != "") {
				$workshop_by_date = mysql_query("SELECT WRKSPID,WRKSPDATE,WRKSPTIME,LOCATION,WRKSPTOPICID FROM WORKSHOP WHERE WRKSPDATE='$date'") or die (mysql_error());
				if(mysql_num_rows($workshop_by_date) != 0) {
					echo "<table border='1'>";
					echo "<tr> <th>Workshop ID</th><th>Date</th> <th>Time</th> <th>Location</th> <th>Topic</th>";
					//keeps getting the next row until there are no more to get
					while($row = mysql_fetch_array($workshop_by_date))
					{
						$workshop_topic = $row['WRKSPTOPICID'];
						$workshop_by_topic=mysql_query("SELECT WRKSPTOPIC FROM WORKSHOPTOPICS WHERE WRKSPTOPICID='$workshop_topic'");
						$workshop_topic = mysql_result($workshop_by_topic,0);
						$workshop_id= $row['WRKSPID'];
						// Print out the contents of each row into a table
						echo "<tr><td>";
						echo "<a href=\"EditEvent.php?id=$workshop_id\">".$row['WRKSPID']."</a>";
						echo "</td><td>";
						echo $row['WRKSPDATE'];
						echo "</td><td>";
						echo $row['WRKSPTIME'];
						echo "</td><td>";
						echo $row['LOCATION'];
						echo "</td><td>";
						echo $workshop_topic;
					}
					echo "</table>";
				}
			}
			
		}
	?> 
</div>

<!-- Begin Side Column -->
<!-- Begin Footer -->

<?php
echo $layout[1];
?>

</body>
</html>
